/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package be.ugent.medirem.persistence.facade;

import be.ugent.medirem.persistence.entity.Administrator;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Thomas Roelens
 */
@Stateless
public class AdministratorDaoBean implements AdministratorDaoLocal {

    @PersistenceContext
    private EntityManager em;

    public Long createAdmin(String username, String password) throws IllegalArgumentException {
        Administrator newAdmin = null;
        try {
            newAdmin = new Administrator(username, password, null, null);
            em.persist(newAdmin);
        } catch (Exception ex) {
            throw new IllegalArgumentException("Username already exists");
        }
        return newAdmin.getId();
    }
}

